-- check_hp
--
local import = import
---@type behavior_ret
local bret = import("bt/bt_plugin/behavior3/behavior_ret")

local M = {
    name = "check_hp",
    type = "Condition",
    desc = "检查血量百分比",
    args = {
        { 'gt', 'float?', '>' },
        { 'lt', 'float?', '<' }
    },
}

local function ret(r)
    return r and bret.SUCCESS or bret.FAIL
end

function M.run(node, env, value)
    local owner = env.owner
    local cfg = node.args
    local hp = owner.hp
    local maxHp = owner.maxHp
    local curVal = hp / maxHp * 100
    if cfg.gt then
        return ret(curVal > cfg.gt)
    elseif cfg.lt then
        return ret(curVal < cfg.lt)
    end
    return bret.FAIL
end

return M

